﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace GSManager
{
    public class PhieuGiaCong
    {
        private int _SoPhieuGC;
        private DateTime _NgayGiaCong;
        private DateTime _NgayGiaoHang;
        private string _MaTho;
        private decimal _TongTien;
        private string _NguoiLapPhieu;
        public int SoPhieuGC
        {
            get { return _SoPhieuGC; }
            set { _SoPhieuGC = value; }
        }
        public DateTime NgayGiaCong
        {
            get { return _NgayGiaCong; }
            set { _NgayGiaCong = value; }
        }
        public DateTime NgayGiaoHang
        {
            get { return _NgayGiaCong; }
            set { _NgayGiaCong = value; }
        }
        public string MaTho
        {
            get { return _MaTho; }
            set { _MaTho = value; }
        }
        public decimal TongTien
        {
            get { return _TongTien; }
            set { _TongTien = value; }
        }
        public string NguoiLapPhieu
        {
            get { return _NguoiLapPhieu; }
            set { _NguoiLapPhieu = value; }
        }
        public int LaySoPhieuGiaCong()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select Max(SoPhieuGC) from PHIEUGIACONG";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            int kq = 0;
            while (r.Read())
            {
                try
                {
                    kq = (int)r[0];
                }
                catch (Exception) { }
            }
            r.Close();
            connect.Close();
            return kq;
        }
        public void LuuPhieuGiaCong()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Insert into PHIEUGIACONG values(?,?,?,?,?,?)";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@SoPhieuGC", OleDbType.Integer);
            cmd.Parameters.Add("@NgayGiaCong", OleDbType.Date);
            cmd.Parameters.Add("@NgayGiaoHang", OleDbType.Date);
            cmd.Parameters.Add("@MaTho", OleDbType.VarChar);
            cmd.Parameters.Add("@TongTien", OleDbType.Decimal);
            cmd.Parameters.Add("@NguoiLapPhieu", OleDbType.VarWChar);
            cmd.Parameters[0].Value = SoPhieuGC;
            cmd.Parameters[1].Value = NgayGiaCong;
            cmd.Parameters[2].Value = NgayGiaoHang;
            cmd.Parameters[3].Value = MaTho;
            cmd.Parameters[4].Value = TongTien;
            cmd.Parameters[5].Value = NguoiLapPhieu;
            cmd.ExecuteNonQuery();
            connect.Close();
        }
    }
}
